package com.untour.im.codec.protocol.serialize.json;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.untour.im.codec.protocol.serialize.Serializer;
import com.untour.im.codec.protocol.serialize.SerializerAlgorithm;

public class JSONSerializer implements Serializer {

    @Override
    public byte getSerializerAlgorithm() {
        return SerializerAlgorithm.JSON;
    }

    @Override
    public byte[] serialize(Object object) {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(TypeReference<T> reference, byte[] bytes) {
        return JSON.parseObject(new String(bytes), reference);
    }
}
